package com.lhx.product.controller;

import com.lhx.common.core.domain.R;
import com.lhx.product.domain.SkuStock;
import com.lhx.product.result.Result;
import com.lhx.product.service.SkuStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：李洪祥
 * @Package：com.lhx.product.controller
 * @Project：lhx-RuoYi
 * @name：SkuStockController
 * @Date：2024/6/3 下午8:59
 */
@RestController
@RequestMapping("/sku")
@Api(tags ="sku库存管理模块", description = "sku库存管理模块")
public class SkuStockController {

    @Autowired
    private SkuStockService skuStockService;

    /**
     * 根据商品ID及sku编码模糊搜索sku库存
     * @param pid 商品ID
     * @param keyword sku编码
     * @return
     */
    @ApiOperation("根据商品ID及sku编码模糊搜索sku库存")
    @GetMapping(value = "/{pid}")
    public R<List<SkuStock>> getList(@PathVariable Long pid, @RequestParam(value = "keyword",required = false) String keyword) {
        List<SkuStock> skuStockList = skuStockService.getList(pid, keyword);
        return R.ok(skuStockList);
    }

    /**
     * 批量更新sku库存信息
     * @param pid 商品ID
     * @param skuStockList sku库存列表
     * @return
     */
    @ApiOperation("批量更新sku库存信息")
    @PostMapping(value = "/update/{pid}")
    public Result update(@PathVariable Long pid, @RequestBody List<SkuStock> skuStockList) {
        int count = skuStockService.update(pid, skuStockList);
        if (count > 0) {
            return Result.success(count);
        }else{
            return Result.error();
        }

    }

}
